<template>
	<view>

		<view>
			<view class="group_2 flex-row">
				<image class="image_2" referrerpolicy="no-referrer"
					src="https://lanhu.oss-cn-beijing.aliyuncs.com/psbly3i425anayxsa1r0py71ueqjx5hya8j608dbd09-c2ea-49f2-9aa1-0982cce02dac"
					@click="back" />
				<text class="text_3">个人实名认证</text>
			</view>
		</view>
		<view class="content">
			<view class="peopleImg">
				<view class="peopleImage" @click="toimg()">
					<view class="peopleImageImage" v-if="!img"></view>
					<image :src="img" style="width:100%;height: 100%;" v-else></image>
				</view>
				<view>点击上传身份证（头像面）</view>
				<view style="font-size: 18rpx;margin: 10rpx 20rpx;">请确保上传证件图片完整不缺角，头像及所有信息均清晰可见</view>

			</view>
			<view class="formInput">
				<view class="uni-form-item ">
					<input class="uni-input" placeholder="请输入" v-model="name" />
					<view>真实姓名：</view>
				</view>
				<view class="uni-form-item ">
					<input class="uni-input" type="text" placeholder="请输入" v-model="identityCard" />
					<view>身份证号：</view>
				</view>

				<view class="renZheng">
					<view hover-class="navigator-hover" class="text_password">
						<button type="default" @click="toAuthentication()">立即认证</button>
					</view>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				name: '', //名字
				identityCard: '', //身份证
				img: null, //身份证照片
				res: null, //身份证照片信息
				url: null, //用户认证请求返回的url
			}
		},

		methods: {
			// 返回上一级页面
			back() {
				uni.redirectTo({
					url: '../../pages/index/index'
				})
			},
			//上传图片
			toimg() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						this.img = res.tempFilePaths[0]
						// console.log(this.img)
					}
				});

			},
			//去认证
			async toAuthentication() {
				let res = await this.checkIdentityCard(this.identityCard)
				if (this.name == '') {
					let title = '请输入正确的名字'
					uni.$showMsg(title)
				} else if (!res) {
					let title = '请输入正确的身份证'
					uni.$showMsg(title)
				} else {
					//发请求
					let param = {
						name: this.name,
						idCode: this.identityCard
					}
					let checkType = uni.getStorageSync("checkType");
					let res
					if (checkType == 1) {
						console.log('企业');
						res = await this.$http('/app/fxqApi/sysUserAuthentication?name=' + this.name + '&idCode=' +
							this.identityCard, 'post')
					} else {
						console.log('个人');
						res = await this.$http('/app/fxqApi/userAuthentication?name=' + this.name + '&idCode=' + this
							.identityCard, 'post')
					}

					console.log('身份认证', res)
					if (res.data.code == 200) {
						this.url = res.data.data
						let title = '认证成功跳转中'
						uni.$showMsg(title)
						window.location.href = res.data.data
					} else {
						let title = res.data.msg
						uni.$showMsg(title)
					}

				}
			},
			//校验身份证
			checkIdentityCard(mobile) {
				return RegExp(
						/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)
					.test(mobile);
			},

		}
	}
</script>

<style scoped>
	.group_2 {
		background-color: rgba(55, 55, 55, 1);
		width: 750rpx;
		height: 100rpx;

	}

	.image_2 {
		width: 20rpx;
		height: 35rpx;
		margin: 36rpx 0 0 61rpx;
	}

	.text_3 {
		width: 166rpx;
		height: 26rpx;
		overflow-wrap: break-word;
		color: rgba(255, 255, 255, 1);
		font-size: 28rpx;
		font-family: SimHei;
		text-align: center;
		white-space: nowrap;
		line-height: 30rpx;
		margin: 41rpx 292rpx 0 211rpx;
	}

	.content {
		font-size: 26rpx;
		padding-top: 38rpx;
		width: 600rpx;
		margin: 0 auto;
	}

	.peopleImg {
		width: 590rpx;
		height: 380rpx;
		background: #E6E6E6;
		border-radius: 30rpx;
		padding-top: 45rpx;
		text-align: center;
		color: #666666;
	}


	.peopleImage {
		width: 420rpx;
		height: 224rpx;
		margin: 0 auto;
		background: #F2F2F2;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 26rpx;
	}

	.peopleImageImage {
		background-image: url(@/static/picture.jpg);
		/* margin-top: 10rpx; */
		width: 180rpx;
		height: 159rpx;
		background-size: cover;

	}

	.formInput {
		margin-top: 40rpx;
	}

	.uni-input {
		width: 420rpx;
		height: 86rpx;
		background: #FFFFFF;
		border: 2rpx solid #C8A556;
		border-radius: 30rpx;
		padding-left: 160rpx;
		margin-top: 30rpx;
		color: #999999;
		font-size: 26rpx;
	}

	.text_password button {
		color: #FFFFFF;
		width: 590rpx;
		height: 86rpx;
		background: #CDAD66;
		border-radius: 30rpx;
		margin-top: 80rpx;
	}

	.uni-form-item {
		position: relative;
	}

	.uni-form-item view {
		position: absolute;
		top: 28rpx;
		left: 30rpx;
	}
</style>
